/************************************************
 * Copyright (c) 2007 ~ 2009, 
 * All rights reserved.
 * Version   : 1.0
 * Author    : lengsh@gmail.com 
 * Date      : 2009.1.2
 ************************************************/

#ifndef  __SOCKET_CONNECTION__H__
#define  __SOCKET_CONNECTION__H__

#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include <string>
#include <iostream>

using namespace std;

namespace mayi {
class sockConn
{
	protected:
		int m_socket;
	public:
		long m_lLasttime;
                long m_lCurtime;
		bool m_bLive;
		int m_iKey;
		string m_sHostname;
		string m_sHostIP;
		int m_iPort;
		int m_iBackup;
		int getStatus() { return m_bLive;  }
		long getLastTime(){ return m_lLasttime; }
                long getCurrTime(){ return m_lCurtime;  }
		sockConn(const char *hname, int port, int ik, int ib ):
			m_sHostname(hname), m_iPort(port), m_iBackup(ib)
	{
		m_iKey = ik;
		m_lLasttime = 0;
		m_bLive = false;
		m_socket = 0;
	}
		~sockConn(){   disConnect();        }
		bool Connect();
		int Proxy(const char *data, unsigned int dlen, char **wbuf,unsigned &wsize, unsigned &wbytes);
		void Print();
	private:
		void disConnect();
};

}
#endif  // __MEMCACHE_CONNECTION__H__
